﻿using UnityEngine;
using UnityEngine.UI;

namespace SuperScrollView
{
    public class SuperListViewItem : MonoBehaviour
    {
        public delegate void OnSelectDelegate(SuperListViewItem item);
        public delegate void OnShowDelegate(SuperListViewItem item);

        public OnSelectDelegate OnSelectItem { set; get; }
        public OnShowDelegate OnShowItem { set; get; }

        public Image mBtn;
        public int mValue;

        public void Init()
        {
            if (mBtn != null)
            {
                ClickEventListener listener = ClickEventListener.Get(mBtn.gameObject);
                listener.SetClickEventHandler(OnClickSelect);
            }
        }

        public void OnClickSelect(GameObject obj)
        {
            OnSelectItem?.Invoke(this);
        }

        public int Value
        {
            get
            {
                return mValue;
            }
            set
            {
                mValue = value;
            }
        }

        public int GetData()
        {
            return mValue;
        }

        public void SetItemData(int value)
        {
            Value = value;
            OnShowItem?.Invoke(this);
        }

        public PanelBase GetPanelBase()
        {
            return GetComponent<PanelBase>();
        }

        public void OnItemSizeChange()
        {
            LoopListViewItem2 item2 = gameObject.GetComponent<LoopListViewItem2>();
            if (item2 != null)
                item2.ParentListView.OnItemSizeChanged(item2.ItemIndex);
        }
    }
}

